﻿imports System.Text 
Public Class clsviGroupUser
	 inherits ADODBU.Recordset 
	 
	 private mFieldList as New ArrayList 
	 private mStrFieldList as string 
	 private mStrSql as string 
	public Sub New()
	mFieldList.Add("viGroupUser.group_name")
	mFieldList.Add("viGroupUser.group_id")
	mFieldList.Add("viGroupUser.Users")
        mStrSql = "Select group_name,zm.group_id,Kd_User from zgroups inner join zmember zm on zgroups.group_id=zm.group_id "
	End Sub
	 
	Public overloads Sub Open( cCriteria as string )
		dim cSql as string 
		 cSql=mStrSql & cCriteria
		mybase.IscanUpdate=true 
		try 
		mybase.Open(cSql,"viGroupUser",me.dbConn)
		Catch e as Exception 
		me.ErrMessage =e.message
		end try
	End sub
 
 
	Public Function GetRowList(dbConn as adodbu.dbconn,cCriteria as string) as ADODBU.RowClassList(of clsviGroupUserRow) 
		Dim cmd As System.Data.IDbCommand = dbConn.DBAFactory.GetCommand
		cmd.CommandText = Me.mstrSql & cCriteria 
		cmd.CommandType = CommandType.Text
		cmd.Connection = dbConn.Connection
		Return GetDataFromReader(cmd.ExecuteReader)
	End Function 
 
	Public Function GetRowList() as ADODBU.RowClassList(of clsviGroupUserRow) 
		Return Me.GetDataFromReader(Me.DataTable.CreateDataReader) 
	End Function 
	private Function GetDataFromReader(ByVal rdr As IDataReader) As ADODBU.RowClassList(Of clsviGroupUserRow)
		dim colData as new ADODBU.RowClassList(of clsviGroupUserRow)
		dim xData as clsviGroupUserRow 
     
		Dim mStr As New System.IO.MemoryStream 
		 
		Do While rdr.Read
		 xData = New clsviGroupUserRow()
			If Not rdr.IsDBNull(0) Then 
			 xData.group_name= rdr.GetString(0)
			End If 
			If Not rdr.IsDBNull(1) Then 
			 xData.group_id= rdr.GetString(1)
			End If 
			If Not rdr.IsDBNull(2) Then 
                xData.Kd_User = rdr.GetInt32(2)
			End If 
			colData.Add(xData)
		Loop
		rdr.close()
		rdr.Dispose()
		Return colData 
	End Function 
 
	Public Function GetClassRow() as clsviGroupUserRow 
		dim crData as new clsviGroupUserRow 
		crData = GetClassRow(me.getcurrentdataRow)
		Return crData 
	End Function 
 
 
	Public Function GetClassRow(recdata as ADODBU.Recordset) as clsviGroupUserRow 
		dim crData as clsviGroupUserRow 
		crData = new clsviGroupUserRow(recdata.getcurrentdataRow) 
		Return crData 
	End Function 
 
 
	Public Function GetClassRow(recdata as DataRow) as clsviGroupUserRow 
		return new clsviGroupUserRow(recdata) 
	End Function 
 
 
	Public Function SaveClassRow(crData as clsviGroupUserRow ,lAddnew as boolean,Optional lTransaction as boolean=false ) as boolean
		dim lSavedata as boolean
		if lAddnew then 
			Mybase.AddNew 
		End if 
		crData.DataSource = me
		crData.SaveToDataSource
		lSaveData=True
		Try 
			Mybase.Update(lTransaction) 
			if Mybase.errMessage.Length<>0 then 
				lSaveData=false
			end if 
		Catch e As Exception
			lSaveData=false
		End Try 
		Return lSavedata 
	End Function 
 

End Class
